Fix MetricsDashboard::selected_index() to return Option<usize>#115
Merged
ryanoneill merged 1 commit intomainfrom Mar 2, 2026
Merged
Fix MetricsDashboard::selected_index() to return Option<usize>#115ryanoneill merged 1 commit intomainfrom
ryanoneill merged 1 commit intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #115 +/- ##
=======================================
Coverage 92.64% 92.64%
=======================================
Files 100 100
Lines 9545 9549 +4
=======================================
+ Hits 8843 8847 +4
Misses 702 702 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Change the internal selected field from usize to Option<usize> so that an empty dashboard correctly reports no selection (None) instead of returning 0 pointing to nothing. - Change selected field from usize to Option<usize> - Default state uses None, new() uses Some(0) when widgets exist - selected_index() now returns Option<usize> - selected_position() now returns Option<(usize, usize)> - Update all navigation logic to wrap/unwrap Option - Update view() to use Option comparison - Update all test assertions to expect Some(value) - Add test_empty_dashboard_selected_index_is_none test Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
30f67af to
5bcacb8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
selectedfield fromusizetoOption<usize>for correctnessselected_index()now returnsOption<usize>(wasusize)selected_position()now returnsOption<(usize, usize)>(was(usize, usize))Noneinstead of0pointing to nothingContext
All other Envision components return
Option<usize>from their index methods. MetricsDashboard was the outlier returning a bareusize. When the widgets vec was empty,selected_index()returned0which was misleading.Test plan
test_empty_dashboard_selected_index_is_nonecovers the empty casecargo clippy --all-targets --all-features -- -D warningsclean🤖 Generated with Claude Code